import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

enum Api {
  list = '/orders/orders/list',
  save='/orders/orders/add',
  edit='/orders/orders/edit',
  get ='/orders/orders/queryById',
  detail ='/orders/orders/detail',
  deleteOne = '/orders/orders/delete',
  deleteBatch = '/orders/orders/deleteBatch',
  importExcel = '/orders/orders/importExcel',
  exportXls = '/orders/orders/exportXls',
  
  //资方产品 - 政策 - 期数
  getTimeLimitSelect = '/policy/policy/getTimeLimitSelect',
  getRateSelect = '/policy/policy/getRateSelect',
}
/**
 * 导出api
 * @param params
 */
export const getExportUrl = Api.exportXls;
/**
 * 导入api
 */
export const getImportUrl = Api.importExcel;
/**
 * 列表接口
 * @param params
 */
export const list = (params) => defHttp.get({url: Api.list, params});

/**
 * 获取订单
 * @param params
 */
export const get = (params) => defHttp.get({url: Api.get, params});

/**
 * 订单详情
 * @param params
 */
export const detail = (params) => defHttp.get({url: Api.detail, params}, { isTransformResponse: false });

/**
 * 删除单个
 * @param params
 * @param handleSuccess
 */
export const deleteOne = (params,handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({ url: Api.deleteOne, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess();
      });
    },
  });
}
/**
 * 批量删除
 * @param params
 * @param handleSuccess
 */
export const batchDelete = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
/**
 * 保存或者更新
 * @param params
 * @param isUpdate 是否是更新数据
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

/**
 * 客户等级下接列表
 * @param params
 */
 export const getTimeLimitSelect = (params) => defHttp.get({url: Api.getTimeLimitSelect, params});

/**
 * 利率
 * @param params
 */
 export const getRateSelect = (params) => defHttp.get({url: Api.getRateSelect, params});